<?php
header('Content-type:text/html;charset=utf-8');
//测试控制器类
class IndexController extends CommonController{
    //动作方法
    public function index(){
    	//调出首页左侧二级菜单的数据
    	$cate = K('Shop_category')->where('pid=0')->order('sort asc')->all();
    	// p($data);
    	//调商品分类子集
    	foreach ($cate as $k => $v) {

			$cate[$k]['son'] = K('Shop_category')->where("pid={$v['cid']}")->all();

    	}
    	
    	foreach ($cate as $k => $v) {
    		$cate[$k]['son'] = K('Shop_category')->where("pid={$v['cid']}")->all();
    		// p($cate);
    		foreach ($v['son'] as $p=> $t) {
    			$cate[$k]['son'][$p]['son'] = K('Shop_category')->where("pid={$t['cid']}")->all();

    		}
    	}
    	// p($cate);die;
    	$this->assign('cate',$cate);
        //调tab切换中商标图片
        $tuData = K('Shop_brand')->all();

        $this->assign('tuData',$tuData);
        //调二级菜单品牌的数据
        $paiData = K('Shop_brand')->limit(8)->all();

        $this->assign('paiData',$paiData);
        //从商品表中调首页商品块的数据
        $kuaiData = M()->join('__shop_goods__ g JOIN __shop_brand__ b ON g.shop_brand_bid=b.bid')->all();
        //满减的处理
        foreach ($kuaiData as $k => $v) {
           $kuaiData[$k]['man']= strstr(ltrim($v['man'],'0'),'.',true);
           $kuaiData[$k]['jian']= strstr(ltrim($v['jian'],'0'),'.',true);
        }
        $this->assign('kuaiData',$kuaiData);
        // p($kuaiData);
        //使用此方法，就会自动去template中找模板
        $this->dis('index');
    }

    //头部购物车异步调用的方法
    public function gengxin(){

        $data = K('Shop_cart')->getField('jiesuan',true);
        foreach ($data as $k => $v) {
            $tem = unserialize($v);
        }
        // p($tem);
        // p($_SESSION);
        $this->ajax($tem);
        
    }
}
